<template>
	<view class="mine" :style="{ paddingTop: systemInfo.statusBarHeight + systemInfo.navBarHeight + 'px' }">
		<!-- 用户信息 -->
		<view class="mine-userinfo">
			<image
				class="userinfo-avatar"
				src="https://img1.baidu.com/it/u=3090108543,3859059787&fm=253&app=138&size=w931&n=0&f=PNG&fmt=auto?sec=1694797200&t=197ed65fc818f30b03cf09032dc1c4d6"
				mode="scaleToFill"
			></image>

			<view class="userinfo-content">
				<template v-if="token">
					<view class="userinfo-content-username">{{ userInfo.nickname }}</view>
					<view class="userinfo-content-ID">ID：1234567890</view>
				</template>
				<template v-else>
					<view class="userinfo-content-username" @click="handleLoginClick">点击登录</view>
				</template>
			</view>
		</view>

		<!-- 功能列表 -->
		<view class="mine-list">
			<template v-for="(item, index) in list" :key="index">
				<view class="list-item" @click="handleListItemClick(item.url)">
					<view class="list-item-left">
						<image class="list-item-left-img" :src="item.icon" mode="widthFix"></image>
						<text class="list-item-left-text">{{ item.label }}</text>
					</view>
					<image class="list-item-right" src="@/static/images/icons/arrow_right.png" mode="scaleToFill"></image>
				</view>
			</template>
		</view>
	</view>
</template>

<script setup>
	import useCommonStore from '@/stores/common/common';
	import { storeToRefs } from 'pinia';
	import { ref } from 'vue';
	import useLoginStore from '@/stores/login/login';

	// - store
	const loginStore = useLoginStore();
	const commonStore = useCommonStore();
	const { systemInfo } = storeToRefs(commonStore);
	const { token, userInfo } = storeToRefs(loginStore);

	// - data
	const list = [
		{
			label: '观看历史',
			icon: '../../../static/images/mine/tv.png',
			url: '/pages_details/history/history'
		},
		{
			label: '用户设置',
			icon: '../../../static/images/mine/setting.png',
			url: '/pages_details/setting/setting'
		},
		{
			label: '帮助中心',
			icon: '../../../static/images/mine/kefu.png',
			url: '/pages_details/help/help'
		},

		{
			label: '关于我们',
			icon: '../../../static/images/mine/about.png',
			url: '/pages_details/history/history'
		}
	];

	const handleListItemClick = (url) => {
		uni.navigateTo({
			url
		});
	};
	const handleLoginClick = () => {
		uni.login({
			success(res) {
				uni.navigateTo({
					url: '/pages/login/login?code=' + res.code
				});
			}
		});
	};
</script>

<style lang="scss">
	.mine {
		position: relative;
		overflow: hidden;
		height: 100%;
		background: linear-gradient(to bottom, #ffe4e1, #ffffff);
		box-sizing: border-box;
		padding: 0 20rpx;

		.mine-userinfo {
			display: flex;
			align-items: center;
			width: 100%;
			height: 120rpx;
			box-sizing: border-box;
			padding-left: 32rpx;
			// margin-top: 30rpx;

			.userinfo-avatar {
				width: 120rpx;
				height: 120rpx;
				border-radius: 50%;
			}

			.userinfo-content {
				color: #121212;
				margin-left: 32rpx;

				.userinfo-content-username {
					font-size: 36rpx;
					font-weight: 600;
				}

				.userinfo-content-ID {
					font-size: 26rpx;
					font-weight: 400;
					margin-top: 10rpx;
				}
			}
		}

		.mine-list {
			margin-top: 40rpx;
			box-sizing: border-box;
			padding: 10rpx 40rpx;
			border-radius: 14rpx;
			background-color: #ffffff;

			.list-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				width: 100%;
				height: 105rpx;

				.list-item-left {
					display: flex;
					align-items: center;
					height: 100%;

					.list-item-left-img {
						width: 35rpx;
					}
					.list-item-left-text {
						font-size: 30rpx;
						font-weight: 500;
						color: #000000;
						margin-left: 20rpx;
					}
				}

				.list-item-right {
					height: 20rpx;
					width: 14rpx;
				}
			}
		}
	}
</style>
